
/*
 * Antonio Canabrava Fraideinberze 7152292
 * Lucas Avelino Sodre Santos      7239086
 * Pedro Rael Garcia               7153021
 */

/*
 * Algorithm of Sieve of Eratosthenes Sequencial
 */
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

#define LETTERS 15
#define LAST_PRIME 10000

char *p;

void sieve();
void print();

int
main(int argc, char *argv[])
{
    int i, j = 0;
    p = (char *) malloc(LAST_PRIME + 1);
    sieve();
    print();
    return 0;
}

void
sieve()
{
    int i;
    int j;
    #pragma omp parallel
    {
        #pragma omp for

        for(i = 0; i <= LAST_PRIME; i++)
            p[i] = 'y';

        #pragma omp for

        for(i = 2; i <= LAST_PRIME; i++)
            #pragma omp parallel
        {
            if(p[i] == 'y')
                #pragma omp for
                for(j = i * i; j <= LAST_PRIME; j += i)
                    p[j] = 'n';
        }
    }
}

void
print()
{
    int i;
    #pragma omp parallel for

    for(i = 2; i <= LAST_PRIME; i++)
        if(p[i] == 'y')
            printf("%d ", i);
}
